Use htmlspecialchars and remove support for &
Fixed bug with closing the last open tags
No need to append an empty string