Improve generateUrl function.