clean up code and add documentation