added try/except around read/write code