better ordering for writing output