Use visitor pattern instead

Courtesy of benji. Thanks!