Cleanup, bug fixes and docstring updates.