Added garbage collection, distance sorting.