Move common code into an MRI function.