Fix missing brackets in DB queries