first try with emulation

still a lot of work to do ... mutable state is hard
refactor a bit memory management