fix encoding and escape issue within handle_data