Fix sorting
Use iterative approach for better memory handling

* Fix test data