Simplified the rewrite logic for the parent/child queries.