alt. implementation of #634, sortOrder type detection fix