Snapshot 4 - set of minimal changes. See FIXME. Added a lot of print debugging statements. I'm in deep crap here.