refactoring to reduce duplication