Improve docstrings and formatting