moved template creation out of file#open block