MAP-964: fix sort ,cleanup some stuff.