set variables correctly, with less trial and error