cleaning up code and adding documentation