Fixed read fsm and write indexing.