fix UnboundLocalError: local variable 'res'

closes #10