Cleanup of cookies related code

@vietj Please review :)