refactored matching of operators to be more general and have less code duplication