Move cookie value building logic to a separate method