Fix bug with return state id and determines last token