Maybe encoding the text only at the end could get rid of this if ...