cleaned up the code, added comments, finalized for submission