Fix checkpointing and add more tests