Fix sorting algorithm, sort similar triggers by length

Fixes #8