writing scaffold, fix some flattoc problem