fix issue where a field may not exist in the data
added support for specifying file encoding, using io.open vs os.open