Cleaned some code, added some comments
Fixed a bug