refactored matchPerfect a bit