added optimization for spheres