Added some comments.
Fixed some bugs.