added custom sort and changed choose_x_functions