updated so that it works for more than one variable