minor refactoring, improve test coverage