fix some bad formatting, rename some variables, add a bunch of docstrings