Refactor directives logic