replaced qSort with std::stable_sort