Add more tests and subsequent guards to matching algorithm