Working switch.

To do - add sorting codes.