Correctly encode input and decode output as UTF-8