add detachedCallback

improve on this as needed