Fix bug in rotation logic