added proper functionality to save attachments.