Attachments support, Code cleanup