refactored visualization logic