Refactored visitor pattern to functional approach

more refactoring to be done...