Refactor url generation