extract pending loop into a module