merge common code as a sub-routines