refactoring to eliminate redundancy