reworked code that selects the plotting function to be a bit cleaner