Reorganize engines into a single hierarchy.
Add tests.
Fix misc bugs.