sort before saving