Add some code to create the rotate grid function