fix bugs in com calculation