Better handling of encoding