Added grad function which allows 2 elements to change in M.  Uses 2nd element 50% of the time. Not working very well.