finishes matching logic