adding comments and cleaning up code