Numerous changes and fixes