change the grep method to make it more efficient