adding more comments and cleaning up code