more memory efficient sort