moved content retrieval and refactored sorting