cleaned up some code, added comments where needed