Add docstrings, improve comments