Fix 'variable is referenced before assignment' error