Refactoring for performance optimizations