handle detached character in more places
fix mislocated end tag
remove unrelated changes
Merge pull request #242 from eve-val/detached-char-checks

handle detached character in more places