Fix bugs, add comments