Dril algorithm rewriten