Fix attachment handling code