Extract common code.