minor refactoring, unit tests