more refactoring for reusability and testability