restructuring of visualisation code