Bugfix for q_sort