UnboundLocalError issue #641