code refactoring, to support unit tests