Change totalValue to method in first example