Correct bug in matching logic