My mistake… you redefine total on each pass through the loop, so detaching it does nothing.
If you were to keep the value of total from one iteration to the next, modifying it in each iteration then you would get the error I was talking about.