Refactored code pt 2

Code now works in the ipython notebook.
iPython mode terminates sampling based on max_samples and not convergence