Avoid manually constructing URLs.

This means that URLs with query parameters are no longer incorrectly
created.

Closes #6, #23, #27.