Properly convert between encodings.