Support more matching situations

Includes a bunch of new tests too