refactoring for the efficient case