refactor to use URI.encode_query