some refactoring to better cater for attachments