working solution for center of mass