Fix some bugs and continue work on AFN program