refactor cookie sending