refactored server waiting