Refactor to match.py