fix tag encoding issues and tweak html_safety some