slight edit to grid code