Lots of changes and fixes