Work with MS-Dos encoding

Also, fix bug in repeat-checking, the fix for which was broken