moved the query outside the loop so it runs one time