improoved check logic