Fixed the AI looping bug but need to figure out what to do when totalTokens ==0 exactly.