fix state and writer