fix encoding bugs on Mac OS X