add comment and fix bugs