Fix sort algorithm