Add comments, refactor cookie clearing