Rewrite the URL building logic

Also removed the trailing commas from the objects.