Adding a mismatch-aware count function