fix the bug reported by Salius

These commits fix some bugs reported on the forum.