added proper validation code for cookie and json