Fixed loop being referenced before assignment