Fix some bugs and try out inverse (not working yet)