Refactor AuthenticationCookieManager and bug fix.