Clean up docstrings, refactor some common logic