fixing invalid byte sequence bug