implement copy on write