callback loop refactoring