Refactoring and optimizations.