fix attach and detach to use instance ref instead of instance name