Calculating moment of inertia