fixing spatial sort