Added sorting for problem 6