Added sorting and output