fixed some bugs related to attachments