Optimizing grid data format and switching to use faster loops.