Refactored directives.js