Switch support, various bugfixes