Correctly handle encoding