Added more type checks to ReadObject/WriteObject methods