Many bugfixes so the notebook works