added while loop to ensure cookie is really checked