fixing residual resampling