Corrects syntax errors
Implements some of the matching logic