moved sorting to DB