fixed bugs in function ...write_scaffold