refactor cookies methods and 404-handling