Refactor UTF-8 handling of error pages.