Using a simple merge sort instead of the supplied Collections.sort, as it was causing a weird exception.