Added template generator handler.
Added interface for template generator.
Refactored gen code to make use of handler.
Fixed issues with refactoring.
Fixed log.