Refactoring for performance