fix error on undefined res and update var name