Fuck.  Add unit tests for engine.  refactor for better testing.  fix
bugs found.

Damn me for not doing unit tests.