Fix early loop exit