private boolean isWellFormed(Region region) {
        if (region.size()==0) return true; // empty squares are well-formed
        
        Stack stack = new Stack(region.size()); // a small local stack
        Iterator it = region.asList().iterator();
        while (it.hasNext()) {
            
            Object next = it.next();
            if (! (next instanceof Matchable)) continue;
            
            Matchable c = (Matchable)next;
            if (c.code()==0) continue; // text doesn't matter, consider only tags
            
            if (c.code()<0) {
                if (stack.size()==0 || stack.peek()+c.code()!=0) return false;
                else stack.pop();       // close tag scope
            }
            else stack.push(c.code()); // save an open tag
        }
        return (stack.size()==0);
    }