Fix: $i is global