big refactor with some limited style changes. Mostly, keeping classes

aware of only the variables they need to know about here.