Change this part
Code:
  set $+(%,mode.,$chan) $1- 


To

Code:
  set $+(%,mode.,$chan) $chan(#).mode 


So it saves the current channel modes.