modified code so gridDict only gets created once