neat trick borrowed from optim.jl convergence code