cleaned up code, added comments and stuff