Added code for modified grid. Also factorized out the acf calculation.