fix infinite loop bug for looking ahead 2 steps