Avoid NRE
minor refactoring
Do not encode the ? character of the query string