Added proper detection and URL building

Awesome stuff. Needs to be refined.