fix bugs in state reset and state init