Matching now essentially written (for training purposes). Still needs testing.