Updated Sort Algorithm