Made sweep function not depenent on plot.