Fix write order generation