First runnable version.
Mostly complete. Still needs a few more tests and fixes.