modified to handle attachments