Do not carry over _cached_written_variables with copy, add test that it doesn't survive transformations