Changed so that logprob value and gradient is calculated in same function call.
This reduces the amount of repeated calculations.