fixed bug #1 and can now write files with the same encoding as the input