fix encoding issue on write operations