Code refactoring and optimizations.