Bug fixes

Bug fixes and improvements. Cleaned up code
Commenting