Fix variables being changed multiple times on eveyr state change