finish the rotate function