Fixes to grid optimization