fix UnboundLocalError: local variable 't' referenced before assignment