Improve calculation of var.gidx