Fix some stuff, add some tests and debugging