added better checks to setmode