First commit.

Mostly working. Still need to implement checkpointing.