refactoring of commonly used routines