Lots of fixes and changes