Fixed many things for ipynb. Tests run perfectl.