Calculation needed to be debugged a bit but now it works.