Modified autop helper function to validate utf encoding.