clean up code and add comments