UnboundLocalError issue #641

Addresses Issue 641