added comments and general code cleanup