optimizations in visualization code