Moved query out of loop.
Moved query out of loop.