Made the switching a bit more robust and simple.