remove some bugs, add comments