refactored common code path