change detach to defer