Rewrite visualization logic