move template handling to separate py file