Several refactorings and changes.