implement rotate logic