Extract module for template rendering

Remove some noise from the main script