Improve testability, add a basic test suite

[ci skip]