Refactor pattern search function.