implemented sort algorithm