read/write fixes; more error handling; style;