some code cleanup and about half the docs