Bug fixes, tests, and more docs