Made a few changes to fix a bug when rotating