move all calculations to cpp