rewritten sgrep