Perfect switching function