Re-implemented the visitor pattern in a more flexible way.