Bug fix for attach function