clean up code, added comments