fix some bugs reported in FS#9707 (some of fix is from the patch by Yoshihisa Uchida...