Clean up some of the code and add more doc-strings