refactoring for redundant code