Fix template generation and module traversal