improve KMP algorithm implement