refactor attaching