refactored into visitors pattern for exercise 2