Fix loop behavior