refactor file rendering from template