Edit: Finally get analytical deriv. correct