fixed handling of encoding