Add more docstrings and clean up a bit