fixing complex calculus for joint calculation