Removed an unnecessary PY2 branch
Added more explicit test cases for chunk functions
Removed double HTML escaping on some exceptions