Improved comments and docstrings