fixed backprop algorithm function