Refactored much of the code to use perpetual averages instead of period average for evaluating cost of items sold.