fixed small bugs, work on #997