Fix referenced before assignment error