fix encoding issue on writing to callbacks