Improve test coverage, small refactorings