Make attach and detach idempotent