Changed printf to fprint(stderr so all debugging goes to stderr except the relay status when reading the state.