Added docstrings & comments, removed some cruft