refactoring of some redundant code