This is the sorting algoritm taken from the old project.