Working bfgs algorithm, although might need additional tuning