Use for x in dict instead of for x in dict.keys()
Get rid of duplicate code
Slightly change derive_and_validate_match invocation arguments. Document validate_match and derive_and_validate_match.