Set up main backpropagation loop