automatically figure out the indexes of different variables used