refactoring code into directives