fix ugly nested foreach at setSorted