add comment and fix some bugs