split grep function out