Test coverage boost and minor refactoring