AFF algorithm