First 'working' version.  It doesn't seem to actually simulate correctly, but it runs end to end