added sorting routine