minor refactoring, additional unit tests