cutting down search space doesn't speed up so refactoring to minimize loc