move wait functions out to module.