Fix: UnboundLocalError: local variable 'fn_name' referenced before assignment