Change URL generation to a function.