Added Class switch and better error messages