Numerous refactorings