Feature/afc refactor

new afc code and tests