introduced smarter way of recursive matching, hopefully