fixing derived variables. 1, 2, 3 done. 3b next. most code from Jeff examples