Optimize state changes