randomized gradient + bug fix for plot code