Changed the way the pin state is set