General cleanup, docstring fixes, testing improvements, bug fixes.