Fix minor bug in checkpointing and streamline code.