Performanance Optimization: Code refactoring