improved reading/writing and errors