Is there a case where the incoming query isn't url encoded? If we're getting a mix of url encoded and not, it might be safer to unquote it, then reencode it. If all the incomeing queries are already url encoded, then we shouldn't need to use urlencode on line 57.