working on rewrite logic for search