Fixed some bugs and commented