rework encoding handling and extract logic to loadHtml method