Fixed bug whereby files were encoded incorrectly, sometimes causing a crash