Correct encoding of query string values in URLs

While no specific encoding issues were really present today, they may appear tomorrow. The code is now more robust by avoiding duplication and using strong types.