added rotate by kTh and detect loop