Fixed problem with min/max in rotation calculation.