WIP. Hardening and refactoring to tests.