Sort attachments to end

Fixes #655.