Add state guards against errors mid-operations