Move waiting for service to helper function.
Add debug output in.