Minor refactors
Add tests, cleanups