CArchive update

* remove duplicated code
* add error checking