fix some bugs I have encountered