Fixed some bugs
Added some comments
Cleaned some code