refactoring to speed up