replaced the switching function