Refactored: moved attachments code to its own handler