optimalized cell code using newtons third law