fix state handling