massive refactoring of the switch system