I made a little script to duplicate channels and amaze your friends so I could test while loops

Code:
alias chanduper {
  ;;variables  
  var %cd.chan = $?="What channel do you want to copy?"  
  var %cd.numchan = $?="How many copies?"
  var %cd.op = $?!="Deop in all of the channels?"
  ;;while loop  
  while (%cd.numchan) {
    var %cd.chan = $instok(%cd.chan,,2,46)
    var %cd.chan = $remove(%cd.chan,.)
    var %cd.join = $addtok(%cd.join,%cd.chan,44)
    if (%cd.op) { mode %cd.chan -o $me }
    dec %cd.numchan
  } 
  join %cd.join
}


It works, but I get error messages equal to the number of copies I wanted to make. The error says:
$chan No such channel
(the channels are still joined though...)

comments?