wordgrep implementation