added optimization to db