refactoring out the duplicate code