Refactoring visualization code