Have a look at this new approach.
I think it should be much easier to recalculate your average costs now.