refactoring out redundant code