fix bug "res is not defined"