modified the rotateGrid method