improve delegation check algorithm