Refactoring and performance improvements.