refactoring distancemesuare to a more general class.