Refactoring and Optimization