Cleaner behavior of flattening script