Fixed bugs in saving task state