Refactoring in match.py