Lots and lots of fixes