Cleaned, added docstrings and comments