Fixed error in implementation of switching function.