improving query to db.