refactore code to use cookies as init parameter (allows better tests, storing cookies in dbs, etc)