Test coverage and small refactoring