Clean up unused code and unnecessary abstractions. Add tests.