Added state change functionality