added a clause to check for attachment