cleanup loops; invoke callback in tests