fix attachment logic