Added array checks to avoid some error logs. Removed usage of ENT_HTML401 flag for htmlentities()