first implementation of dmin and plot functions