badly working rotate function