Implement BFGS algorithm