Clean up and add more docstrings