Change f_df and loss to accept list of parameters and return list of gradients