Improve cookie function, to not trust cookies implicitly