finish wiriteCookie and closeCookie