refactor handling of directives