move unicode detection to a separate function