fix error in UnboundLocalError