refactors match logic again