Mr. Hadley said Washington is working very closely with both Pakistan and Afghanistan to counter the threat .