Moved template generation to library