Rewrite the URL building logic

Also removed the trailing commas from the objects.
Merge pull request #15 from Robertof/master

Fix compatibility problems (closure js compressor)