Added sorting code to Sessions code