Fixed UnboundLocalError exception