Fixed bug with wrong output order.
Fixed empty rows not being output.