Copy codes from L-BFGS-B