Moved cookie creation to a listener