adding a few more docstrings and reindenting the whole thing