Address PR

Clean up code, add docstring, move things around