Updated backprop algorithm function