modified function ...write_scaffold