Some major refactorings