Move logic from template to module.