secondary sort in emr, various other improvements