Better parsing of query string variables

Fixes #361