fix bug on generating state