Some docstrings and refactor.