With function for calculating center of mass