make db kv store thread safe
refactor cookie management