Added support for sorting and randomisation