Clarify key-matching logic, more tests.