restructured visualization code and added comments