Moved an unnecessary db access out side of a loop.
Database has more columns
Merged.