Extensive refactor. AFF is done.