Merge the rest of the patches

Now it actually works and passes the test suite