cleaned up some code, added comments