EG: finally got the basic idea working
EG: WIP; complete rewrite to make it testable