use 'ex' variable instead of recomputing 'exp(-xx)'