fix bugs, add comments