implemented matching-based boundary detection