Merge both backprop functions into one