Modified SGD PMF example to make it easier to read
Abstracted functionality slightly to allow for automation