optimized code for finding files