Replace search method with KMP algorithm