implemented attach/detach; store state in metadata.