Fix sorting problem and other things in the new CpEntityManager and CpRelationManager implementations.