fixing cookie function bugs