Added semi-generic writing, moved most memory to shared/weak pointers