refactored common code