fixed a couple bugs in reading/writing

and added a few "round trip" tests...though a lot more would be good.