Fix bugs in KMP matcher