updated validation and removal of cookies with some private methods to perform the logic for these common functionalities