refactoring for AFP