Generalize mainLoop for multiple Plots