Added sorting function