Change implementation to visitor pattern