add sorting and a subtle fix in vectorsAlongDimension