To add to napa's suggestion, some windows ain't got no $chan or #. The only two realistic places are nicklist and channel.