Refactor visitors so that they can be used in more abstract manner.

Signed-off-by: Rami Ylimäki <rami.ylimaki@vincit.fi>