A huge set of fixes and changes