Added docstrings, cleaned up code