refactor query string parsing