Refactor URL building