Refactor getCookie