You are looping through the compiled list twice, just after one another, put it in a single foreach loop and break after you find something.