Adding method to handle state changes