Fix bugs in scaffold generation