Simplified the logic and also improved the performance of query string parsing.