enhance attachment detection regarding the attachment flag