fixing undefined res variable