Refactoring for efficiency