refactored to use a service for storing total earnings