Implement sorting in models