added the trick calculating logic