Added sorting function.