added maxWait option