Additional unit test coverage and small refactoring