fix some bugs from issue #83