Fix attach function