change rotation logic to fix rotation arrangement bug