Added sorting routine