Sorting it out solution