reworking to be more easily usable in ipython