Added totalValue function to code