Improved formatting, added some comments & expanded docstrings.