fix grep function. isPrefix handling bug