fix for UnboundLocalError