Extract to temp mat helper function