Code cleanup

Cleaned up code and added comments