Fix cookie bug and clean up cookie package API.