Fixed a bug in checkpointing