Fix bugs in AFN program