Various bug, docstring, and PEP8 fixes.