added cleanup attachments code