Align with tweaked sort API.  Fix some sillyness caused by a
misunderstanding of the sort API.  

Also fixed edge cases with cycle detection and leaf handling.

Work around another bug in the exist implementation where it doesn't
respect the requested codeSystemVersion while resolving associations.