Modify the objective function with gradient such that it now works.  Also changed optimization to use fmin_l_bfgs_b, which works even more.