Adding proper wait logic for server