Cleaned up & rewrote directives generator (fixes #2).