Refactor generic directive code structure.