Improved html checking to be reliable