added cookie script and reshuffled definitions for events in the appropriate places