moved sorting into model