adding comments and clean up code