service loop refactor