wait logic added