[fixes #1] extract to a visitor pattern