Fix file and output encoding issues