server: refactor query string parsing