Refactorings, some optimizations.