move attach/detach to Loop for locking.