added reverse grid function