Fixed some bugs and updated comments