Add support for matching in two directions