better, although more complicated, system for switch