Backport of resample fix.