Added code to do grid cell detrending