refactor attachment creation