Corrected my Script to detect the State of the global switch