various code cleanup while I hunt for the unit template bug