Fixed bug in AF implementation. Added unit test for non-AF cases. Needed for #2347.