Refactored visitor pattern implementation