fix dphi calculation