Updated sort

Works for input.