refactor generateUrl method