Refactor to work with ipython parallel