refactor code to get target for grep