#5 Implement matching algorithm