Added some docstrings.
Docstrings and refactoring.