Cleaned up a bit, added docstrings