Fixed more gradient stuff, par_test works properly now. Need to backport these changes to par_opt for source localization.