$ cat debug.prompt
The following Python function is supposed to return the top-N most frequent words in a string, sorted by frequency descending and alphabetically for ties. It has exactly 3 bugs. Find each bug, explain what it does wrong, fix it, and show the corrected function.
```python
from collections import Counter
def top_words(text: str, n: int = 10) -> list[str]:
words = text.lower().split()
words = [w.strip('.,!?;:\'"') for w in words]
counts = Counter(words)
ranked = sorted(counts.items(), key=lambda x: (-x[1], x[0]))
return [word for word, count in ranked[:n] if count > 1]
```
Test cases that expose the bugs:
- `top_words('the cat sat on the mat the', 3)` should return `['the', 'cat', 'mat']`
(3 most frequent; cat/mat/sat tie at 1 occurrence — alphabetical breaks the tie)
- `top_words('a a b b c', 2)` should return `['a', 'b']`
- `top_words('hello world', 5)` should return `['hello', 'world']`
For each bug: (1) quote the buggy line, (2) explain what it does wrong, (3) show the fix.