Moved calculation of iD around. Now including opts$resamples (instead of opts$n, which didn't work.)