Various new changes, much refactoring