refactored.
the whole 'commutations' function was replaced by two additional lines in matchesPattern