Refactor and correct text encoding.