refactoring for speed