Fix trigger sorting algorithm