sort before processing