adding conditional debug output for state changes