Added basic error checking for htmlentities