fix checkpoint bugs and unit tests