Some additions and refactorings