refactoring for better testing