fix state change bugs