Match refactored and tested