Removed debugging redundant call to optim, time drops to 3.1 seconds
for n=1000 from 89 seconds.
Fixed binding issue for density.deriv