Fixed UnboundLocalError in log statement