implementation of generate and plot functions