refactor KMP more