refactor of color_sort