Dirty BFGS implementation (does not completely work)