Move logic into build_url