get_targets algorithm optimized a little