Improved query calls to database to use lists instead.