Refactor based on comments. Clean up some docstrings.