Fixed broken for statement will enter a dead loop