modularized the plotting