lots and lots of fixes