Changes to fill_template() that reduce memory usage without having