Added the code for the sphere case.