refactoring out duplicate code