Refactor common directive code structure.