move helper methods to helper file
nest visualizations within functions and remove document-wide listeners