generic sort