Fixed saving bug that lead to inconsistent state