Improve attachments functionality, bugfixes