documentation and cleaning up some code