The status of isKept never changes within this loop and makes a DB query each time its called.  You should call this once outside the loop and store the results.