Refactor common code in attach/detach