added Mike's version of learning switch