More code cleanup, common code for generating directives