Working version of table generation code for ipython notebook, some fixes