Added a test to make sure the loss is monotonically decreasing with LBFGS, and some code clean up.