simplified and improved cookie validation