Refactor Naive and KMP