improved url creation logic