separated out encodings, errors writing to file