Fix "variable referenced before assignment" error