Performance improvements and code refactoring.