Fix handling of variables; add model tests