Fixed some bugs. Added some comments.