added sorting, and improved output