Fixes sort algorithm to prevent destructive sorting, resolves functional issue with sort