Some progress on attachments. Code seriously needs cleanup.