Old script I cant get to work in V3

Here is a script from another site written in Oct 2006, it creates queue trees for each PPPoE user currently logged on, Ive corrected it for syntax so it at least runs, but its only creating queue for the first PPPoE-in interface it finds, and its not creating the sub queue at all. Anyone care to take a stab at fixing it?

{

:local "mark-p2p" P2P
:local "mark-non-p2p"  HTTP
:local "ifacename"
:local "queuename"


/queue tree{
#
# First remove any invalid queues. This happens whenever a pppoe
# connection is dropped - even if the connection returns the queue is
# forever lost.
#
:foreach j in [find invalid=yes] do {
#
# MT Bug  "disabled" entries are considered to be "invalid" and
# would be deleted here - this keeps any "disabled" entries
#
:if (![get $j disabled]=yes) do {
remove $j
}
}
}

/interface {
:foreach i in [find type="pppoe-in"] do {
:set ifacename ([get $i name])

# This will print the list of interfaces found (debugging)
# :put ($ifacename)

:set queuename ([:pick $ifacename 1 ([:len $ifacename] - 1)])

# Print the queue name to the console (debugging)
 :put $queuename


/queue tree{


# Create a "master-queue". The parent is the virtual interface
# (pppoe) not the physical interface
:if ([:len [find name=($queuename . " all out")]] = 0) do {
add name=($queuename . " all out") parent=$ifacename \
queue=qtype_p2p priority=1 limit-at=50000 \
max-limit=400000
}


# MT Bug  It is possible to add a sub-queue to a "disabled" parent
# queue, and the sub-queue is not made "invalid" despite the fact
# that the parent queue "does not exist" (ie is "invalid")
# This prevents adding queue to a disabled parent
:if (![get [find name=($queuename . " all out")] disabled]=yes) do {
# Create a "sub-queue" for p2p traffic. The parent is the
# "master-queue" for the virtual interface (pppoe)
:if ([:len [find name=($queuename . " p2p out")]] = 0) do {
add name=($queuename . " p2p out") \
parent=($queuename . "all out") \
packet-mark=$"mark-p2p" queue=qtype_p2p priority=8 \
limit-at=50000 max-limit=200000
}

# Create a "sub-queue" for non-p2p traffic. The parent is the
# "master-queue" for the virtual interface (pppoe)
:if ([:len [find name=($queuename . " non-p2p out")]] = 0) do {
add name=($queuename . " non-p2p out") \
parent=($queuename . "all out") \
packet-mark=$"mark-non-p2p"  queue=qtype_non_p2p \
priority=1 limit-at=0 max-limit=0
}
# Depending on how you have set up packet marking in mangle you
# can create "sub-queues" here for any other type of traffic sent out # on this virtual interface (pppoe)
}
}
}
}
}