Restructure

Separated the switching code