Updated for extend and ipython notebook