refine KMP