Move cookie getter and setter to utils

Fix #451.