refactored code to use a common checkHTML function