Minor bugfixes to matching